﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JobbJakt
{
    public partial class Applications
    {

        public static int InsertApplications(Applications applications)
        {
            var query =
                JobbJaktDB.Applications.Where(
                    a => a.AdvertisementID == applications.AdvertisementID &&
                        a.UserName == applications.UserName)
                    .ToList();
            if (query.Count() == 0)
            {
                JobbJaktDB.Applications.Add(applications);
                return JobbJaktDB.Save();
            }

            return 0;
        }
        public static int UpdateApplications(Applications applications)
        {
            JobbJaktDB.Applications.AddOrUpdate(applications);
            return JobbJaktDB.Save();
        }

        public static Applications GetApplications(int advertisementid)
        {
            var query = JobbJaktDB.Applications
                .SingleOrDefault(a => a.AdvertisementID == advertisementid);
            return query;
        }
        public static List<Applications> GetApplicationsToList()
        {
            var query = JobbJaktDB.Applications.Select(n => n).ToList();
            return query;
        }
    }
}
